<template>
    <div class="minWidth" id="app">
        <router-view />
        <div v-if="loaded">
            <login></login>
            <authentication></authentication>
        </div>
    </div>
</template>
<script>
import login from '@/components/login/index.vue'
import authentication from '@/components/authentication'
import Socket from '@/mixins/socket'

export default {
    components: {
        login,
        authentication,
    },
    computed: {
        user() {
            return this.$store.state.user.user
        },
    },
    data() {
        return {
            loaded: false,
        }
    },
    mixins: [Socket],
    watch: {
        user(newVal, oldVal) {
            if (newVal.hasOwnProperty('id') && oldVal.hasOwnProperty('id')) {
                if (newVal.id != oldVal.id) {
                    this.connect()
                }
            } else if (!newVal.hasOwnProperty('id') && oldVal.hasOwnProperty('id')) {
                this.disconnect()
            } else if (newVal.hasOwnProperty('id') && !oldVal.hasOwnProperty('id')) {
                this.connect()
            }
        },
    },
    mounted() {
        if (this.user && this.user.id) {
            this.connect()
        }
        let that = this
        setTimeout(() => {
            that.loaded = true
        }, 1000)

        const userAgent = navigator.userAgent
        let isAndroid = /Android/i.test(userAgent)
        let isIOS = /iPhone|iPad|iPod/i.test(userAgent)
        let isPC = !this.isAndroid && !this.isIOS

        if (isAndroid) {
            // window.open(, '_blank');
            location.href = 'http://ground.miazh.com/#/'
        }

        if (isIOS) {
            location.href = 'itms-apps://itunes.apple.com/cn/app/id6467184869?mt=8'
        }

        this.getCoinName()
        this.getConfig()
      
    },
    methods:{
        getCoinName(){
            this.$request
                .get('/config/config/coin_name')
                .then((res) => {
                    console.log('coinName',res.result)
                    this.$store.dispatch('system/coinName',res.result)
                    console.log('coinName',this.$store.state.system.coin_name)
                })
                .catch(() => { })
        },
        getConfig() {
            this.$request.get('/config/webview_links_more').then((res) => {
                 console.log(res, 11212)
                this.$store.state.config = res
            })
        },
     
    }
}
</script>
<style lang="scss">
@import 'assets/css/public-style';
@import 'assets/css/iconfont.css';

#app {
    overflow: hidden;
}
</style>
